package com.company.Offer;

import java.util.ArrayList;
import java.util.List;

public class LK13 {
    public static void main(String[] args) {
        System.out.println(Math.abs(1-2));
        String a = "1231";
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append(a.charAt(0));
        System.out.println(stringBuilder.toString());
        convert("PAYPALISHIRING"
                ,3);

    }
    public static int movingCount(int m, int n, int k) {
        int sum = 1;
        int[][] arr = new int[m][n];
        arr[0][0] = 1;
        for(int i =0;i<m;i++){
            for(int j=0;j<n;j++){
                int num = 0;
                int x = i;
                int y = j;
                while(x!=0){
                    num += x%10;
                    x /=10;
                }
                while(y!=0){
                    num += y%10;
                    y /=10;
                }
                if(num<=k){
                    if(i-1>=0&&arr[i-1][j]!=0){
                        sum++;
                        arr[i][j] = 1;
                        continue;
                    }
                    if(i+1<m&&arr[i+1][j]!=0){
                        sum++;
                        arr[i][j] = 1;
                        continue;
                    }
                    if(j-1>=0&&arr[i][j-1]!=0){
                        sum++;
                        arr[i][j] = 1;
                        continue;
                    }
                    if(j+1<n&&arr[i][j+1]!=0){
                        sum++;
                        arr[i][j] = 1;
                        continue;
                    }
                }
            }
        }
        return sum;
    }
    public static String convert(String s, int numRows) {
        List<StringBuilder> list = new ArrayList<>();
        if(s.length()==1||s.length()<=numRows)return s;
        for(int i =0;i<numRows;i++){
            list.add(new StringBuilder());
        }
        int x = 0;
        while(x<s.length()){
            int n = 0;
            while(x<s.length()&&n<numRows){
                list.get(n).append(s.charAt(x));
                n++;
                x++;
            }
            n = n-2;
            while(x<s.length()&&n>0){
                n--;
                list.get(n).append(s.charAt(x));
                x++;
            }
        }
        StringBuilder str = new StringBuilder();
        for(int i =0;i<numRows;i++){
            str.append(list.get(i));
        }
        return str.toString();
    }
}
